<?php

class MBase_Modules extends Db_Record {

	public function setup () {
		$this->table_name = "modules";

		$this->hasColumn('id', Db_Column::COLUMN_TYPES_INT, 11, array(
			Db_Column::COLUMN_PROPERTY_AUTOINCREMENT => true,
			Db_Column::COLUMN_PROPERTY_PRIMARY => true,
			Db_Column::COLUMN_PROPERTY_NOTNULL => true,
		));

		$this->hasColumn('name', Db_Column::COLUMN_TYPES_VARCHAR, 250);
		
		$this->hasColumn('title', Db_Column::COLUMN_TYPES_VARCHAR, 250, array(
			Db_Column::COLUMN_PROPERTY_NOTNULL => true,
		));
		
		$this->hasColumn('parent', Db_Column::COLUMN_TYPES_INT, 11, array(
			Db_Column::COLUMN_PROPERTY_NOTNULL => true,
			Db_Column::COLUMN_PROPERTY_DEFAULT => 0,
		));
		
		$this->hasColumn('order', Db_Column::COLUMN_TYPES_INT, 2, array(
			Db_Column::COLUMN_PROPERTY_NOTNULL => true,
			Db_Column::COLUMN_PROPERTY_DEFAULT => 0,
		));
		
		$this->hasMany('modules', array(
			'alias' => 'Items',
			'foreign' => 'parent',
		));
		
		$this->hasOne('modules', array(
			'alias' => 'Parent',
			'local' => 'parent',
			'foreign' => 'id',
		));
	}

}